/* 纯绝对定位 */
/* .box {
    position: absolute;
    width: 200px;
    height: 100px;
    background: red;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    margin: auto;
} */
/* 绝对定位加负外边距 */
/* .box {
    position: absolute;
    width: 200px;
    height: 100px;
    background: red;
    left: 50%;
    top: 50%;
    margin-left: -100px;
    margin-top: -50px;
} */
/* 绝对定位加平移 */
/* .box {
    position: absolute;
    width: 200px;
    height: 100px;
    background: red;
    left: 50%;
    top: 50%;
    transform: translate(-50%, -50%);
} */
/* 使用flex实现 */
html,
body {
    height: 100%;
}

body {
    background: gray;
    display: flex;
    align-items: center;
    justify-content: center;
}

.box {
    width: 200px;
    height: 100px;
    background: red;
}
/* 使用grid实现 */
html,
body {
    height: 100%;
}

body {
    background: gray;
    display: grid;
    /*   align-content: center;
  justify-content: center; */
    /* align-content和justify-content的简写 */
    place-content: center;
}

.box {
    width: 200px;
    height: 100px;
    background: red;
}
/* 使用table加外边距实现 */
 /* display: table时padding会失效 
 display: table-row时margin、padding同时失效
  display: table-cell时margin会失效 */
.box {
    background: red;
    height: 300px;
    width: 600px;
    display: table-cell;
    vertical-align: middle;
}

.child {
    width: 200px;
    height: 200px;
    background: lightgreen;
    margin: 0 auto;
}

